package com.krtech.wecard.module.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.krtech.wecard.module.pub.entity.ApplicationManagement;
import com.krtech.wecard.module.sys.entity.StatisticalMain;
import java.util.List;
import java.util.Map;

import com.krtech.wecard.module.sys.pojo.TopVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface StatisticalMainMapper extends BaseMapper<StatisticalMain> {
    int updateBatch(List<StatisticalMain> list);

    int batchInsert(@Param("list") List<StatisticalMain> list);

    @Update("update sys_statistical_main set count = (count + 1) where id = #{id}")
    int increment(@Param("id") Integer id);

    public List<StatisticalMain> getListByaccessTime(@Param("accessTime") String accessTime,@Param("moduleName") String moduleName);

    /**
     * 是否考虑某个时间段？
     *
     * @return
     */
    public List<TopVo> top();

    /**
     *
     * @param userCode
     * @return
     */
    @Select("select c2.*,c1.count from (\n" +
            "SELECT module_name, sum(count) AS count FROM sys_statistical_main WHERE user_code = #{userCode} AND del_flag = 0 GROUP BY module_name ORDER BY count DESC \n" +
            ") as c1 \n" +
            "LEFT JOIN pub_application_management as c2 \n" +
            "on c1.module_name = c2.name \n" +
            "where `status` is not null and `status` = 1 ORDER BY c1.count DESC")
    public List<ApplicationManagement> CommonApplication(String userCode);
}